// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    // 从数据库中获取轮播图数据
    const bannersCollection = db.collection('banners')
    const { data: banners } = await bannersCollection
      .orderBy('order', 'asc') // 按照顺序排序
      .get()
    
    return {
      success: true,
      data: banners
    }
  } catch (err) {
    return {
      success: false,
      errMsg: err.message
    }
  }
}